import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by coy on 2017/9/11.
 */
public class ThoughtWork {
    private static final String[] plcaes = {"A", "B", "C", "D"};
    private LinkedList<HashMap<String,Table>> vectors = null;
    public static void main(String [] args) throws ParseException{
        ThoughtWork tw = new ThoughtWork();
        tw.Initial();

        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            String str =  sc.nextLine();
            if("".equals(str))
                break;
            String[] input = str.split(" ");
            if(!solveInput(input))
                continue;
            tw.dealBook(input);
        }
        tw.calculate();

    }
    public void calculate(){
        System.out.println("收入汇总： " + "\n---");
        Iterator<HashMap<String,Table>> it = vectors.iterator();
        double total_sum = 0;
        for(int i = 0;i < vectors.size();i++){
            double sum = 0;
            System.out.println("场地：" + plcaes[i]);
            HashMap<String,Table> map = it.next();
            map.forEach((k, v)->{
                v.getResult().forEach(item->System.out.println(k + item));
            });
            for(Map.Entry<String,Table> table:map.entrySet()){
                sum += table.getValue().getTotal();
            }
            total_sum += sum;
            System.out.println("小计： " + sum + "元\n");
        }
        System.out.println("---\n总计： " + total_sum + "元");
    }

    public boolean dealBook(String[] input){
        if(input.length < 4)
            return false;
        try{
            String user = input[0];
            String date = input[1];
            String[] time = input[2].split("~");
            int startTime = Integer.parseInt(time[0].substring(0,2));
            int endTime = Integer.parseInt(time[1].substring(0,2));
            int index = input[3].charAt(0) - 'A';
            boolean cancel = (input.length == 5);
            int price_index = getWeekOfDate(date);

            Iterator<HashMap<String,Table>> iterator = vectors.iterator();
            HashMap<String,Table> map = null;
            while(index-- >= 0)
                map = iterator.next();

            if(map.containsKey(date)){
                Table table = map.get(date);
                if(cancel) {
                    if (table.cancel(user, startTime, endTime)){
                        map.put(date, table);
                        System.out.println("Success: the booking is accepted!");
                    }
                    else
                        System.out.println("Error: the booking being cancelled does not exist!");
                }
                else{
                    if(table.book(user, startTime, endTime)){
                        map.put(date, table);
                        System.out.println("Success: the booking is accepted!");
                    }
                    else
                        System.out.println("Error: the booking conflicts with existing bookings!");
                }

            }else {
                map.put(date, new Table(user, startTime, endTime, price_index));
                System.out.println("Success: the booking is accepted!");
            }

        }catch (ParseException e){
            e.printStackTrace();
        }

        return true;
    }

    private boolean Initial(){
        vectors = new LinkedList<>();
        for(int i = 0;i < plcaes.length;i++)
            vectors.add(new HashMap<String,Table>());
        return true;
    }
    public static boolean solveInput(String[] inputs){
        if(inputs.length < 4){
            System.out.println("Error: the booking is invalid!");
            return false;
        }
        for(int i = 0;i < inputs.length;i++){
            switch(i){
                case 0:
                    //System.out.println("用户名：" + inputs[i]);
                    break;
                case 1:
                    String date_str =inputs[1];
                    SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                    dateFormat.setLenient(false);
                    try {
                        Date date = dateFormat.parse(date_str);

                    } catch (Exception ex){
                        System.out.println("Error: the booking is invalid!");
                        return false;
                    }
                    //System.out.println("日期：" + inputs[i]);
                    break;
                case 2:
                    String[] date = inputs[i].split("~");

                    /* 已经用另外的判定代替
                    if(!"00".equals(date[0].substring(3)) || !"00".equals(date[1].substring(3))){
                        System.out.println("Error: the booking is invalid!");
                        return false;
                    }
                    if(Integer.parseInt(date[0].substring(0,2)) >= Integer.parseInt(date[1].substring(0,2))){
                        System.out.println("Error: the booking is invalid!");
                        return false;
                    }
                    */
                    //判断输入的预定时间是否是有效预定时间
                    SimpleDateFormat timeFormat=new SimpleDateFormat("HH:mm");
                    Date beforeTime;
                    Date behindTime;
                    Date firstTime;
                    Date lastTime;
                    try{
                        beforeTime=timeFormat.parse(date[0]);
                        behindTime=timeFormat.parse(date[1]);
                        firstTime=timeFormat.parse("9:00");
                        lastTime=timeFormat.parse("22:00");
                        if(beforeTime.before(firstTime)||beforeTime.after(lastTime)||
                                behindTime.before(firstTime)||behindTime.after(lastTime)
                                ||beforeTime.equals(behindTime)||beforeTime.after(behindTime)){
                            System.out.println("Error: the booking is invalid!");
                            return false;
                        }
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    //System.out.println("起止时间段：" + inputs[i]);
                    break;
                case 3:
                    if(!Arrays.asList(plcaes).contains(inputs[i])){
                        System.out.println("Error: the booking is invalid!");
                        return false;
                    }
                    //System.out.println("场地： " + inputs[i]);
                    break;
                case 4:
                    if(!"C".equals(inputs[i])){
                        System.out.println("Error: the booking is invalid!");
                        return false;
                    }
                    break;
                default:
                    System.out.println("Error: the booking is invalid!");
                    return false;
            }
        }
        return true;
    }

    public  static int getWeekOfDate(String date) throws ParseException{
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE");
        String week = sdf.format(sd.parse(date));
        return ("星期六".equals(week) || "星期日".equals(week)) ? 1 : 0;
    }
    public boolean bookingInfoCheck(String bookingInfo){
        String[] infoArray=bookingInfo.split(" ");
        Date beforeTime;
        Date behindTime;
        Date firstTime;
        Date lastTime;
        if(infoArray.length>=4){
            try {
                String date_str = infoArray[1];
                SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
                dateFormat.setLenient(false);
                Date date = dateFormat.parse(date_str);

            } catch (Exception ex){
                System.out.println("Error: the booking is invalid!");
                return false;
            }
            if(!"A".equals(infoArray[3])&&!"B".equals(infoArray[3])&&!"C".equals(infoArray[3])&&!"D".equals(infoArray[3])){
                System.out.println("Error: the booking is invalid!");
                return false;
            }
            String[] time=infoArray[2].split("~");
            SimpleDateFormat timeFormat=new SimpleDateFormat("HH:mm");

            try{
                beforeTime=timeFormat.parse(time[0]);
                behindTime=timeFormat.parse(time[1]);
                firstTime=timeFormat.parse("9:00");
                lastTime=timeFormat.parse("22:00");
                if(beforeTime.before(firstTime)||beforeTime.after(lastTime)||
                        behindTime.before(firstTime)||behindTime.after(lastTime)
                        ||beforeTime.equals(behindTime)){
                    System.out.println("Error: the booking is invalid!");
                    return false;
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if(infoArray.length==5&&!"C".equals(infoArray[4])){
                System.out.println("Error: the booking is invalid!");
                return false;
            }
            System.out.println("Success: the booking is accepted!");
            return true;
        }else{
            System.out.println("Error: the booking is invalid!");
            return false;
        }

    }
}
